package com.situ.stmall.manager.controller.api;

import com.situ.stmall.manager.entity.Result;
import com.situ.stmall.manager.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/upload")
public class APIUploadController {
    @Value("${upload.path}")
    //使用spring的EL表达式，读取配置文件中，upload.path属性的值
    private String path;
    /**
     * 上传文件使用post请求
     */
    @PostMapping
    public Result upload(MultipartFile file){
        String fileName = UploadUtil.save(file,"D:/upload/");
        if(fileName != null){
            return Result.success(fileName);
        }else {
            return Result.error("上传失败");
        }
    }
}
